<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            height: 10000px;
        }
        div {
            display: none;
            width: 50px;
            height: 50px;
            text-align: center;
            line-height: 50px;
            position: fixed;
            right: 50px;
            bottom: 50px;
            background: palegreen;
        }
    </style>
</head>
<body>
    <div id="top">top</div>
    <script>
        var uptop = document.querySelector('div');
        // console.log(uptop)
        window.onscroll = function(){
            var scrolltop = document.documentElement.scrollTop || document.body.scrollTop
            if(scrolltop > window.innerHeight){
                uptop.style.display = 'block';
            }else{
                uptop.style.display = 'none';
            }
        }
        uptop.onclick = function(){
            var scrtop = document.documentElement.scrollTop || document.body.scrollTop
            var time = setInterval(function(){
                scrtop -= 50+scrtop/5;
                window.scrollTo(0,scrtop)
                if(scrtop <= 0 ){
                    clearInterval(time);
                }
            },50)
        }
    </script>
</body>
</html>